<?php


class Object
{
}

class Error
{
  function Error($message)
  {
    if ($message === "")
    {
      $message = false;
    }
    $this->db = new Object();
    $this->db->error = new Object();
    $this->db->error->message = $message;
    $this->send();
  }
  
  function send()
  {
    fwrite(STDERR, utf8_encode(json_encode($this->db) . "\n"));
  }
}

class Output
{
  function Output($message)
  {
    $this->db = new Object();
    $this->db->output = new Object();
    $this->db->output->message = $message;
    $this->send();
  }
  
  function send()
  {
    fwrite(STDOUT, utf8_encode(json_encode($this->db) . "\n"));
  }
}

class ChannelList
{
  function ChannelList($id)
  {
    if (!isset($id))
    {
      throw "ChannelList constructor requires an id as its first argument!";
    }
    $this->jsontv = new Object();
    $this->jsontv->id = $id;
    $this->jsontv->channels = new Object();
  }
  
  function addChannel($channelObject)
  {
    if (!isset($channelObject))
    {
      throw "ChannelList->addChannel requires a channel object!";
    }
    else if (!isset($channelList->id))
    {
      throw "ChannelList->addChannel got an object but it did not have the required id attribute!";
    }
    else if (isset($this->jsontv->channels[$channelObject->id]))
    {
      throw "Channel with id " . $channelObject->id ." already exists in channel list with id " . $this->id . "!";
    }
    else
    {
      $this->jsontv->channels[$channelObject->id] = $channelObject;
    }
  }
}
?>